/*
 * @Author: HX
 * @Date: 2024-12-07 14:09:13
 * @LastEditors: HX
 * @LastEditTime: 2024-12-07 16:28:05
 */
import global from "../core/global.js";

let Pipeline = {
  add(options, cb) {
    let pipeLayer = new SSmap.GeoJsonPipelineLayer();
    if (options.url) {
      pipeLayer.geoJson = options.url;
    }
    if (options.stringGeo) {
      pipeLayer.addString(options.stringGeo);
    }
    pipeLayer.color = options.color || SSmap.Color.fromRgb(0, 255, 212, 52); //填充颜色
    pipeLayer.alpha = options.alpha == undefined ? 0.2 : options.alpha; //透明度
    if (options.startAltitudeField) {
      pipeLayer.startAltitudeField = options.startAltitudeField; //开始（底部）的海拔值 属性中的字段命名
    }
    if (options.endAltitudeField) {
      pipeLayer.endAltitudeField = options.endAltitudeField; //结束（顶部）的海拔值 属性中的字段命名
    }
    if (options.radiusField) {
      pipeLayer.radiusField = options.radiusField; //半径 属性中的字段命名
    }
    if (options.colorField) {
      pipeLayer.colorField = options.colorField; //颜色 属性中的字段命名
    }
    if (options.radius) {
      pipeLayer.radius = options.radius;
    }
    if (options.shapeRadius && options.shapesubdivision) {
      //半径 细分
      let shape = SSmap.GisUtil.computeCircle(
        options.shapeRadius,
        options.shapesubdivision
      );
      pipeLayer.addShape(shape); //形状
    }
    //高亮颜色
    if (options.highLightColor) {
      pipeLayer.highLightColor = options.highLightColor;
    }
    pipeLayer.usedProperties =
      options.usedProperties === undefined ? false : options.usedProperties; //是否读取geojson文件中的属性
    pipeLayer.depthTest =
      options.depthTest == undefined ? true : options.depthTest; //是否进行深度检测
    if (options.id) pipeLayer.tag = options.id
    let id = global.PipelineStore.add(pipeLayer, options.id);
    pipeLayer.readyPromise.then(function () {
      console.log('pipeLayer', pipeLayer)
      cb && cb(id);
    });
    pipeLayer.create();
    return id;
  },
  _getPipeline(id) {
    let pipeLayer = global.PipelineStore.get(id)
    return pipeLayer
  },
  remove(id) {
    global.PipelineStore.has(id) && global.PipelineStore.remove(id);
  },
  removeAll() {
    global.PipelineStore.removeAll();
  },
};
export { Pipeline };